package org.zn.mvcbase.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.zn.mvcbase.page.PaginationUtility;
import org.zn.mvcbase.response.AmazeUIDataTableBean;
import org.zn.mvcbase.response.DataMessage;
import org.zn.mvcbase.response.DetailedMessage;
import org.zn.mvcbase.response.EasyUIDataGridBean;
import org.zn.mvcbase.response.MainStatus;
import org.zn.mvcbase.response.Metadata;
import org.zn.mvcbase.response.PaginationData;
import org.zn.mvcbase.response.ResponseMessage;
import org.zn.mvcbase.response.ResponseMessageFactory;
import org.zn.mvcbase.response.VariableDateGrid;
import org.zn.mvcbase.validate.ValidatedResult;

/**
 * @Copyright: Copyright (c) 2016
 * @author: 周楠
 * @date 2016年3月16日 上午11:11:48
 */

public class ResponseMessageController extends PaginationController {

	@Autowired
	protected ResponseMessageFactory rmf;
	
	public ResponseMessage responseMessage(String mainstatus,PaginationUtility page, 
			Map<String, Object> dataMap,Class<ResponseMessage> type) {
		return rmf.getResponseMessage(new Metadata(mainstatus, page, null, dataMap, null), type);
		
	}
	
	public ResponseMessage responseMessage(String mainstatus,PaginationUtility page, ValidatedResult validresult
			,Map<String, Object> dataMap,Object  detail,Class<ResponseMessage> type) {
		return rmf.getResponseMessage(new Metadata(mainstatus, page, validresult, dataMap, detail), type);
	}
	
	public ResponseMessage responseMessage(String mainstatus,Map<String,Object> dataMap,Class<ResponseMessage> type) {
		return rmf.getResponseMessage(new Metadata(mainstatus, null, null, dataMap, null), type);
	}
	
	

	/**
	 * 
	 * @Description: 返回主状态信息，通过传入状态码调用
	 * @MethodName:getMainStatus
	 * @author: Lan Yuan
	 * @email: lanyuan@91isoft.com
	 * @date 2016年3月25日 上午8:51:16
	 * @version V1.0
	 * @param ms
	 *            状态码
	 * @return
	 */
	public ResponseMessage getMainStatus(String ms) {
		return rmf.getResponseMessage(new Metadata(ms, null, null, null, null), MainStatus.class);
	}

	/**
	 * 
	 * @Description: 返回主状态及分页信息，通过传入状态码和分页对象
	 * @MethodName:getPaginationMessage
	 * @author: Lan Yuan
	 * @email: lanyuan@91isoft.com
	 * @date 2016年3月25日 上午9:03:35
	 * @version V1.0
	 * @param ms
	 * @return
	 */
	public ResponseMessage getPaginationMessage(String ms) {
		return rmf.getResponseMessage(new Metadata(ms, getPaginationUtility(), null, null, null), PaginationData.class);
	}

	/**
	 * 返回验证信息
	 * 
	 * @MethodName:getValidatedMessage
	 * @author: Lan Yuan
	 * @email: lanyuan@91isoft.com
	 * @date 2016年3月25日 上午9:03:52
	 * @version V1.0
	 * @return
	 */
	public ResponseMessage getValidatedMessage() {
		return getValidatedResult().getValidatedMessage();
	}

	/**
	 * 
	 * @Description: 返回主状态码及自定义扩展数据（如详细对象、页面信息等）
	 * @MethodName:getDataMessage
	 * @author: Lan Yuan
	 * @email: lanyuan@91isoft.com
	 * @date 2016年3月25日 上午9:04:13
	 * @version V1.0
	 * @param ms
	 *            主状态码
	 * @param datamap
	 *            自定义扩展数据
	 * @return
	 */
	public ResponseMessage map(String ms, Map<String, Object> datamap) {
		return rmf.getResponseMessage(new Metadata(ms, null, null, datamap, null), DataMessage.class);
	}
	
	public ResponseMessage getDetailMessage(String ms, Object obj) {
		return rmf.getResponseMessage(new Metadata(ms, null, null, null, obj), DetailedMessage.class);
	}
	
	

	/**
	 * 
	 * @Description: 返回主状态信息
	 * @MethodName:getEasyUIDataGridMessage
	 * @author: Lan Yuan
	 * @email: lanyuan@91isoft.com
	 * @date 2016年3月25日 上午9:07:55
	 * @version V1.0
	 * @param ms
	 * @return
	 */
	public ResponseMessage getEasyUIDataGridMessage(String ms) {
		return rmf.getResponseMessage(new Metadata(ms, getPaginationUtility(), null, null, null),EasyUIDataGridBean.class);
	}
	
	/**
	 * 
	 * @Description: 返回主状态信息
	 * @MethodName:getEasyUIDataGridMessage
	 * @author: Lan Yuan
	 * @email: lanyuan@91isoft.com
	 * @date 2016年3月25日 上午9:07:55
	 * @version V1.0
	 * @param ms
	 * @return
	 */
	public ResponseMessage getAmazeUIDataTableMessage(String ms) {
		return rmf.getResponseMessage(new Metadata(ms, getPaginationUtility(), null, null, null),AmazeUIDataTableBean.class);
	}
	
	
	public ResponseMessage getDataTableMessage(String ms) {
		return rmf.getResponseMessage(new Metadata(ms, getPaginationUtility(), null, null, null),VariableDateGrid.class);
	}

}
